package com.atguigu.jxc.service.impl;

import com.atguigu.jxc.dao.OverflowListDao;
import com.atguigu.jxc.dao.OverflowListGoodsDao;
import com.atguigu.jxc.entity.DamageList;
import com.atguigu.jxc.entity.OverflowList;
import com.atguigu.jxc.entity.OverflowListGoods;
import com.atguigu.jxc.service.OverflowListService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class OverflowListServiceImpl implements OverflowListService {

    @Autowired
    private OverflowListDao overflowListDao;

    @Autowired
    private OverflowListGoodsDao overflowListGoodsDao;


    @Override
    @Transactional
    public int save(OverflowList overflowList) {
        //先保存 报溢单
        int save = overflowListDao.save(overflowList);

        //获取报溢单 id
        String overflowListId = overflowList.getOverflowListId();

        //获取报溢单  关联的商品列表
        List<OverflowListGoods> overflowListGoodsList = overflowList.getOverflowListGoodsList();
        for (OverflowListGoods overflowListGoods : overflowListGoodsList) {
            overflowListGoods.setOverflowListId(Integer.parseInt(overflowListId));
            int save1 = overflowListGoodsDao.save(overflowListGoods);
        }


        return save;
    }

    @Override
    public List<OverflowList> getListByDate(String sTime, String eTime) {
        return overflowListDao.getListByDate(sTime,eTime);
    }

    @Override
    public List<OverflowListGoods> getByListId(Integer overflowListId) {
        return overflowListGoodsDao.getByListId(overflowListId);
    }
}
